import {elements} from "../globalData/elements.js";

/**
 * 判断坐标是否位于指定的矩形框内
 */
export const isInArea = (pointX,pointY,x,y,width,height) => {
    return x<=pointX&&y<=pointY&&(x+width)>=pointX&&(y+height)>=pointY
}

/**
 * 判断坐标是否位于指定的元素上
 */
export const isOnElement = (pointX,pointY,element) => {
    return isInArea(pointX,pointY,element.x,element.y,element.w,element.h)
}

export const isOnElements = (pointX,pointY,elements) => {
    for (let element of elements) {
        let b = isOnElement(pointX,pointY,element)
        if(b) return element
    }
    return false
}

export const getTouchTarget = (pointX,pointY) => {
    let arr = []
    for (let element of elements) {
        let b =isOnElement(pointX,pointY,element[1])
        if(b){
            arr.push(element[0])
        }
    }
    return  arr
}